module.exports = app => {
  const { STRING, INTEGER } = app.Sequelize;

  const Topic = app.model.define('topic', {
    id: {
      type: INTEGER,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
    },
    title: {
      type: STRING(255),
      allowNull: false,
    },
    isDeleted: {
      type: INTEGER,
      defaultValue: 0,
    },
  }, {
    timestamps: true,
    underscored: false,
  });

  Topic.associate = function () {

    Topic.hasMany(app.model.TopicTeacher, { foreignKey: 'topicId', as: 'teachers' });

    Topic.hasMany(app.model.TopicLesson, { foreignKey: 'topicId', as: 'lessons' });

    Topic.hasMany(app.model.TopicMaterial, { foreignKey: 'topicId', as: 'materials' });
  };



  return Topic;
};

